﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace YunDrug.Migrations
{
    public partial class initv11 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_App_机构信息_机构类别_机构类别Id",
                table: "App_机构信息");

            migrationBuilder.DropForeignKey(
                name: "FK_字典项_App_字典信息_字典信息编码",
                table: "字典项");

            migrationBuilder.DropIndex(
                name: "IX_App_机构信息_机构类别Id",
                table: "App_机构信息");

            migrationBuilder.DropPrimaryKey(
                name: "PK_字典项",
                table: "字典项");

            migrationBuilder.DropPrimaryKey(
                name: "PK_机构类别",
                table: "机构类别");

            migrationBuilder.DropColumn(
                name: "机构类别Id",
                table: "App_机构信息");

            migrationBuilder.DropColumn(
                name: "Descrtion",
                table: "机构类别");

            migrationBuilder.DropColumn(
                name: "Name",
                table: "机构类别");

            migrationBuilder.RenameTable(
                name: "字典项",
                newName: "App_字典项");

            migrationBuilder.RenameTable(
                name: "机构类别",
                newName: "App_机构类别");

            migrationBuilder.RenameIndex(
                name: "IX_字典项_字典信息编码",
                table: "App_字典项",
                newName: "IX_App_字典项_字典信息编码");

            migrationBuilder.AlterColumn<string>(
                name: "机构说明",
                table: "App_机构信息",
                maxLength: 255,
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(max)",
                oldNullable: true);

            migrationBuilder.AddColumn<Guid>(
                name: "机构类别编码",
                table: "App_机构信息",
                nullable: false,
                defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));

            migrationBuilder.AddColumn<string>(
                name: "类别名称",
                table: "App_机构类别",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "类别说明",
                table: "App_机构类别",
                nullable: true);

            migrationBuilder.AddPrimaryKey(
                name: "PK_App_字典项",
                table: "App_字典项",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_App_机构类别",
                table: "App_机构类别",
                column: "Id");

            migrationBuilder.CreateIndex(
                name: "IX_App_机构信息_机构类别编码",
                table: "App_机构信息",
                column: "机构类别编码");

            migrationBuilder.AddForeignKey(
                name: "FK_App_机构信息_App_机构类别_机构类别编码",
                table: "App_机构信息",
                column: "机构类别编码",
                principalTable: "App_机构类别",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_App_字典项_App_字典信息_字典信息编码",
                table: "App_字典项",
                column: "字典信息编码",
                principalTable: "App_字典信息",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_App_机构信息_App_机构类别_机构类别编码",
                table: "App_机构信息");

            migrationBuilder.DropForeignKey(
                name: "FK_App_字典项_App_字典信息_字典信息编码",
                table: "App_字典项");

            migrationBuilder.DropIndex(
                name: "IX_App_机构信息_机构类别编码",
                table: "App_机构信息");

            migrationBuilder.DropPrimaryKey(
                name: "PK_App_字典项",
                table: "App_字典项");

            migrationBuilder.DropPrimaryKey(
                name: "PK_App_机构类别",
                table: "App_机构类别");

            migrationBuilder.DropColumn(
                name: "机构类别编码",
                table: "App_机构信息");

            migrationBuilder.DropColumn(
                name: "类别名称",
                table: "App_机构类别");

            migrationBuilder.DropColumn(
                name: "类别说明",
                table: "App_机构类别");

            migrationBuilder.RenameTable(
                name: "App_字典项",
                newName: "字典项");

            migrationBuilder.RenameTable(
                name: "App_机构类别",
                newName: "机构类别");

            migrationBuilder.RenameIndex(
                name: "IX_App_字典项_字典信息编码",
                table: "字典项",
                newName: "IX_字典项_字典信息编码");

            migrationBuilder.AlterColumn<string>(
                name: "机构说明",
                table: "App_机构信息",
                type: "nvarchar(max)",
                nullable: true,
                oldClrType: typeof(string),
                oldMaxLength: 255,
                oldNullable: true);

            migrationBuilder.AddColumn<Guid>(
                name: "机构类别Id",
                table: "App_机构信息",
                type: "uniqueidentifier",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "Descrtion",
                table: "机构类别",
                type: "nvarchar(max)",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "Name",
                table: "机构类别",
                type: "nvarchar(max)",
                nullable: true);

            migrationBuilder.AddPrimaryKey(
                name: "PK_字典项",
                table: "字典项",
                column: "Id");

            migrationBuilder.AddPrimaryKey(
                name: "PK_机构类别",
                table: "机构类别",
                column: "Id");

            migrationBuilder.CreateIndex(
                name: "IX_App_机构信息_机构类别Id",
                table: "App_机构信息",
                column: "机构类别Id");

            migrationBuilder.AddForeignKey(
                name: "FK_App_机构信息_机构类别_机构类别Id",
                table: "App_机构信息",
                column: "机构类别Id",
                principalTable: "机构类别",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_字典项_App_字典信息_字典信息编码",
                table: "字典项",
                column: "字典信息编码",
                principalTable: "App_字典信息",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
